#include "nm_exception.h"


extern "C" {
typedef void (__cdecl *_se_translator_function)(ULONG ExceptionCode, EXCEPTION_POINTERS* pExceptionPointers);
_se_translator_function __cdecl set_se_translator(_se_translator_function);
}



KException::KException(EXCEPTION_POINTERS const &info)
{
   EXCEPTION_RECORD const &exception = *(info.ExceptionRecord);
   m_IP = exception.ExceptionAddress;
   m_Status = exception.ExceptionCode;
}


void KException::Install()
{
   set_se_translator(Translator);
}



KExceptionAccessViolation::KExceptionAccessViolation(EXCEPTION_POINTERS const &info) :
	KException(info)
{
   EXCEPTION_RECORD const &exception = *(info.ExceptionRecord);
   m_Addr = (PVOID) exception.ExceptionInformation[1];
   m_IsWrite = (exception.ExceptionInformation[0]==1);
}


void __cdecl KException::Translator(ULONG Code, EXCEPTION_POINTERS *info)
{
	if (Code != STATUS_ACCESS_VIOLATION) {
		throw KException(*info);
	}
	else {
		throw KExceptionAccessViolation(*info);
	}
}

